package com.dmap.analysispoint.controller.background;

import com.dmap.analysispoint.controller.background.param.CountParam;
import com.dmap.analysispoint.service.*;
import com.dmap.base.constants.Constant;
import com.dmap.base.vo.BaseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * \* @author:zhouhao
 * \* Date:10/05/2018
 * \* Description:
 * \*
 */
@Api(value = "统计分析处理", description = "background/统计分析处理")
@Controller
@RequestMapping(value = "/background/dmap-analysis-point-server/v2/")

public class CountAnalysisController {

    @Resource
    private RealTimeCountAnalysisService realTimeCountAnalysisService;
    @Resource
    private HistoryTrendAnalysisService historyTrendAnalysisService;

    @ResponseBody
    @ApiOperation(value = "查询APP版本名",
            notes = "1.传入所要查询的参数，参数为公司编号、渠道、项目编号、设备固件编号、设备固件版本号、app版本号、查询的开始时间、查询的结束时间,参数根据权限和需要选填,其中查询的开始时间、查询的结束时间\n" +
                    "2.返回符合查询条件的实时分析模块所有信息和数据")
    @RequestMapping(value = "selectAppVersionList", method = RequestMethod.POST)
    public BaseVo selectAppVersionList(@RequestBody CountParam param) {
        BaseVo baseVo = new BaseVo();
        if (param == null) {
            baseVo.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            baseVo.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
        }
        List<String> selectAppVersionList = historyTrendAnalysisService.selectAppVersionList(param);
        baseVo.setData(selectAppVersionList);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "实时分析",
            notes = "1.传入所要查询的参数，参数为公司编号、渠道、项目编号、设备固件编号、设备固件版本号、app版本号、查询的开始时间、查询的结束时间,参数根据权限和需要选填,其中查询的开始时间、查询的结束时间分别为当天零点时间戳、当前查询时间的时间戳\n" +
                    "2.返回符合查询条件的实时分析模块所有信息和数据")
    @RequestMapping(value = "realTimeCountAnalysisList", method = RequestMethod.POST)
    public BaseVo realTimeCountAnalysisList(@RequestBody CountParam param) {
        BaseVo baseVo = new BaseVo();
        if (param == null) {
            baseVo.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            baseVo.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
        }
        List<List> realTimeCountAnalysisList = realTimeCountAnalysisService.realTimeCountAnalysisList(param);
        baseVo.setData(realTimeCountAnalysisList);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "历史趋势中关键指标",
            notes = "1.传入所要查询的参数，参数为公司编号、渠道、项目编号、设备固件编号、设备固件版本号、app版本号、查询的开始时间、查询的结束时间,参数根据权限和需要选填,其中查询的开始时间、查询的结束时间分别为查询时间段第一天的零点时间戳、第七天的零点时间戳\n" +
                    "2.返回符合查询条件的历史趋势模块中关键指标部分所有信息和数据")
    @RequestMapping(value = "keyIndicatorList", method = RequestMethod.POST)
    public BaseVo keyIndicatorList(@RequestBody CountParam param) {
        BaseVo baseVo = new BaseVo();
        if (param == null) {
            baseVo.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            baseVo.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
        }
        List<List> keyIndicatorList = historyTrendAnalysisService.keyIndicatorList(param);
        baseVo.setData(keyIndicatorList);
        return baseVo;
    }

    @ResponseBody
    @ApiOperation(value = "历史趋势中整体趋势和详细数据部分",
            notes = "1.传入所要查询的参数，参数为公司编号、渠道、项目编号、设备固件编号、设备固件版本号、app版本号、查询的开始时间、查询的结束时间,参数根据权限和需要选填,其中查询的开始时间、查询的结束时间分别为查询时间段第一天的零点时间戳、最后一天的零点时间戳\n" +
                    "2.返回符合查询条件的历史趋势中整体趋势和详细数据部分所有信息和数据")
    @RequestMapping(value = "historyTrendAnalysisList", method = RequestMethod.POST)
    public BaseVo historyTrendAnalysisList(@RequestBody CountParam param) {
        BaseVo baseVo = new BaseVo();
        if (param == null) {
            baseVo.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            baseVo.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
        }
        List<List> historyTrendAnalysisList = historyTrendAnalysisService.historyTrendAnalysisList(param);
        baseVo.setData(historyTrendAnalysisList);
        return baseVo;
    }
}
